/*
 * File: exercise18.cpp
 * -------------------
 * Cipher function 
 * compile command :
 * g++ -Wall -g exercise18.cpp -o exercise18 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include "simpio.h"
#include <string>
using namespace std;

string Cipher(string str, string key);

int main()
{
	cout<<"Letter substitution cipher."<<endl;
	string key = getLine("Enter a 26-letter key: ");
	string str = getLine("Enter a message: ");
	cout<<"Encoded message: "<<Cipher(str, key)<<endl;
	return 0;
}

string Cipher(string str, string key)
{
	int nchars = str.length();
	string result = "";
	for(int i = 0; i < nchars; i++)
	{
		if(isupper(str[i]))
			result += key[str[i] - 'A'];
		else 
			result += str[i];
	}
	return result;
}
